---

- name: Copy java artifact
  ansible.builtin.copy:
    src: "{{ java_artifact }}"
    dest: "/app/{{ java_artifact }}"

- name: Create service starter
  ansible.builtin.template:
    src: service-start.sh.j2
    dest: /app/service-starter.sh
    mode: 0755

- name: Upload consul app properties
  ansible.builtin.copy:
    src: "{{ java_app_consul_property_dump }}"
    dest: "/app/consul-properties.json"
  when: apply_consul_configuration_for_java_app == true
    
- name: Apply app properties
  ansible.builtin.shell:
    cmd: |
      consul kv import @consul-properties.json
    chdir: /app/
  when: apply_consul_configuration_for_java_app == true

- name: Enable and restart java-application service
  ansible.builtin.service:
    name: java-application
    daemon_reload: true
    state: restarted
